package servlet;

import pojo.Dept;
//import pojo.User;
import service.DeptService;
//import service.UserService;
import service.impl.DeptServiceimpl;
//import service.impl.UserServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
@WebServlet(urlPatterns = {"/dept"})

public class DeptServlet extends HttpServlet {
    //创建业务层对象  多态
    DeptService deptService = new DeptServiceimpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Dept> depts = null;
        try {
            depts = deptService.findAll();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        req.setAttribute("depts",depts);
        req.getRequestDispatcher("/dept.jsp").forward(req,resp);

    }
}
